package com.topisv.tms.utils.http;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;


@Component
@Lazy(false)
public class MessageThread {
	private static final Logger log = LoggerFactory.getLogger(MessageThread.class);
	
	private Thread threadConsumer=null;
	
	private Thread threadSendBatch=null;
	
	private Thread threadSendMessage=null;
	
	private Thread threadWMSPrinter=null;
	
	private Thread threadSynchOrdenoLog=null;
	
	private Thread threadPreBillMailSender=null;
	
//	private Thread edbTradeGet=null;
//	
//	private Thread edbProductGet=null;
//	
//	private Thread edbInStoreGet=null;
//	
//	private Thread edbOutStoreGet=null;
	
	@Autowired
	private SynchroQueueMessage consumerMessage=null;
	@Autowired
	private SynchroSendBatchMessage synchroSendBatchMessage=null;
	@Autowired
	private SynchroSendMessage synchroSendMessage=null;
	@Autowired
	private SynchroWMSPrintre synchroWMSPrintre=null;
	@Autowired
	private SynchOrdenoLog synchOrdenoLog=null;
	@Autowired
	private PreBillMailSender preBillMailSender=null;
	@Autowired
	private SynchroInvoicePrinter synchroInvoicePrinter=null;
//	@Autowired
//	private SynchroEdbPorductGet synchroEdbProductGet=null;
//	
//	@Autowired
//	private SynchroEdbTradeGet synchroEdbTradeGet=null;
//	
//	@Autowired
//	private SynchroEdbInStoreGet synchroEdbInStoreGet=null;
//	
//	@Autowired
//	private SynchroEdbOutStoreGet synchroEdbOutStoreGet=null;
	
	public void startSynchOrdenoLog(){
		log.info("WMS自动上传日志开始了");
		if(threadSynchOrdenoLog==null||!threadSynchOrdenoLog.isAlive()){
			threadSynchOrdenoLog=new Thread(synchOrdenoLog);
			synchOrdenoLog.setFlag(true);
			threadSynchOrdenoLog.start();
		}
		log.info("WMS自动上传日志完成");
	}
	
//	public void startEdbProductGet(){
//		log.info("自动同步E店宝商品信息开始了");
//		if(edbProductGet==null||!edbProductGet.isAlive()){
//			edbProductGet=new Thread(synchroEdbProductGet);
//			synchroEdbProductGet.setFlag(true);
//			edbProductGet.start();
//		}
//	}
	
//	public void startEdbTradeGet(){
//		log.info("自动同步E店宝订单信息开始了");
//		if(edbTradeGet==null||!edbTradeGet.isAlive()){
//			edbTradeGet=new Thread(synchroEdbTradeGet);
//			synchroEdbTradeGet.setFlag(true);
//			edbTradeGet.start();
//		}
//	}
//	public void startEdbInStoreGet(){
//		log.info("自动同步E店宝入库单信息开始了");
//		if(edbInStoreGet==null||!edbInStoreGet.isAlive()){
//			edbInStoreGet=new Thread(synchroEdbInStoreGet);
//			synchroEdbInStoreGet.setFlag(true);
//			edbInStoreGet.start();
//		}
//	}
	
//	public void startEdbOutStoreGet(){
//		log.info("自动同步E店宝出库单信息开始了");
//		if(edbOutStoreGet==null||!edbOutStoreGet.isAlive()){
//			edbOutStoreGet=new Thread(synchroEdbOutStoreGet);
//			synchroEdbOutStoreGet.setFlag(true);
//			edbOutStoreGet.start();
//		}
//	}
	
	public void stopSynchOrdenoLog(){
		log.info("WMS开始停止上传订单日志");
		synchOrdenoLog.setFlag(false);
	}
	
//	public void stopEdbProductGet(){
//		log.info("WMS开始停止自动同步E店宝商品信息");
//		synchroEdbProductGet.setFlag(false);
//	}
	
//	public void stopEdbTradeGet(){
//		log.info("WMS开始停止自动同步E店宝订单信息");
//		synchroEdbTradeGet.setFlag(false);
//	}
	
//	public void stopEdbInStoreGet(){
//		log.info("WMS开始停止自动同步E店宝入库单信息");
//		synchroEdbInStoreGet.setFlag(false);
//	}
	
//	public void stopEdbOutStoreGet(){
//		log.info("WMS开始停止自动同步E店宝出库单信息");
//		synchroEdbOutStoreGet.setFlag(false);
//	}
	
	@PostConstruct
	public void start(){
		log.info("自动推送出库批次开始了。。。");
		threadSendBatch=new Thread(synchroSendBatchMessage);
		threadSendBatch.start();
		
		log.info("自动发货开始了。。。");
		threadConsumer=new Thread(consumerMessage);
		threadConsumer.start();
		
		log.info("JMS消息自动推送开始了。。。");
		threadSendMessage=new Thread(synchroSendMessage);
		threadSendMessage.start();
		
		log.info("自动修改订单打印状态开始了");
		threadWMSPrinter=new Thread(synchroWMSPrintre);
		threadWMSPrinter.start();
		
		log.info("预约入库单邮件监控开始.");
		threadPreBillMailSender=new Thread(preBillMailSender);
		threadPreBillMailSender.start();
		
		log.info("修改发票打印状态");
		new Thread(synchroInvoicePrinter).start();
		
//		startEdbTradeGet();
	}

}
